package com.zl.tby.vo.exp;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.zl.tby.core.context.service.UcService;
import com.zl.tby.model.TbyAnimalPlant;
import com.zl.tby.service.ITbySpeciesCategoryService;
import com.zl.tby.service.ITbyTypeLevelService;
import lombok.Data;
import org.noear.solon.Solon;
import org.noear.solon.validation.annotation.Length;
import org.noear.solon.validation.annotation.NotBlank;
import org.noear.wood.utils.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 动植物管理表单bean
 * @author sunjiaxing
 * @version 1.0
 * @since 2024/8/7 23:33
 */
@Data
public class TbyAnimalPlantExportExcel {
    /**中文名*/
    @ExcelProperty(value = "中文名", index = 0)
    @ColumnWidth(15)
    private String chName;
    /**中文拼音*/
    @ExcelProperty(value = "中文拼音", index = 1)
    @ColumnWidth(15)
    private String chPinyin;
    /**学名*/
    @ExcelProperty(value = "学名", index = 2)
    @ColumnWidth(15)
    private String scientificName;
    /**国家保护等级*/
    @ExcelProperty(value = "国家保护等级", index = 3)
    @ColumnWidth(15)
    private String protectionLevel;
    /**是否旗舰物种*/
    @ExcelProperty(value = "是否旗舰物种", index = 4)
    @ColumnWidth(15)
    private String isSpecies;
    /**旗舰物种顺序*/
    @ExcelProperty(value = "旗舰物种顺序", index = 5)
    @ColumnWidth(15)
    private String flagshipSpeciesSeq;
    @ExcelProperty(value = "物种分类", index = 6)
    @ColumnWidth(15)
    private String typeLevel;
    /**物种分类*/
    @ExcelProperty(value = "分类级别", index = 7)
    @ColumnWidth(15)
    private String levelNames;
    @ExcelProperty(value = "cites", index = 8)
    @ColumnWidth(15)
    private String cites;
    @ExcelProperty(value = "iucn", index = 9)
    @ColumnWidth(15)
    private String iucn;
    /**中国珍惜濒危真菌*/
    @ExcelProperty(value = "中国珍惜濒危真菌", index = 10)
    @ColumnWidth(15)
    private String isCherish;
    @ExcelProperty(value = "冠名物种", index = 11)
    @ColumnWidth(15)
    private String sponsorship;
    /**是否为图例*/
    @ExcelProperty(value = "是否为图例", index = 12)
    @ColumnWidth(15)
    private String legend;
    @ExcelProperty(value = "生态学", index = 13)
    @ColumnWidth(15)
    private String ecology;
    /**经纬度*/
    @ExcelProperty(value = "经纬度", index = 14)
    @ColumnWidth(15)
    private String latitudeLongitude;
    /**简介*/
    @ExcelProperty(value = "简介", index = 15)
    @ColumnWidth(15)
    private String remark;

    public static List<TbyAnimalPlantExportExcel> createList(List<TbyAnimalPlant> dbList) {
        UcService ucService = Solon.context().getBean(UcService.class);
        ITbySpeciesCategoryService speciesCategoryService = Solon.context().getBean(ITbySpeciesCategoryService.class);
        Map<String, String> protectionLevel = ucService.getDictMap("protection_level");
        Map<String, String> ecology = ucService.getDictMap("ecology");
        Map<String, String> cites = ucService.getDictMap("cites");
        Map<String, String> iucn = ucService.getDictMap("iucn");
        Map<String, String> flagshipSpeciesSeq = ucService.getDictMap("flagship_species_seq");
        Map<Long, String> speciesMap = speciesCategoryService.mapData();

        List<TbyAnimalPlantExportExcel> dataList = new ArrayList<>();
        for (TbyAnimalPlant entity : dbList) {
            TbyAnimalPlantExportExcel excel = new TbyAnimalPlantExportExcel();
            excel.setChName(entity.getChName());
            excel.setChPinyin(entity.getChPinyin());
            excel.setScientificName(entity.getScientificName());
            excel.setLevelNames(entity.getLevelNames());
            excel.setTypeLevel(speciesMap.containsKey(entity.getTypeLevel()) ? speciesMap.get(entity.getTypeLevel()) : "");
            excel.setLatitudeLongitude(entity.getLatitudeLongitude());
            excel.setRemark(entity.getRemark());
            if (StringUtils.isNotEmpty(entity.getIsSpecies())) {
                excel.setIsSpecies(entity.getIsSpecies().equals("0") ? "是" : "否");
            }
            if (entity.getIsCherish() != null) {
                excel.setIsCherish(entity.getIsCherish().intValue() == 1 ? "是" : "否");
            }
            if (StringUtils.isNotEmpty(entity.getProtectionLevel())) {
                excel.setProtectionLevel(protectionLevel.get(entity.getProtectionLevel()));
            }
            if (StringUtils.isNotEmpty(entity.getEcology())) {
                excel.setEcology(ecology.get(entity.getEcology()));
            }
            if (StringUtils.isNotEmpty(entity.getCites())) {
                excel.setCites(cites.get(entity.getCites()));
            }
            if (StringUtils.isNotEmpty(entity.getIucn())) {
                excel.setIucn(iucn.get(entity.getIucn()));
            }
            if (StringUtils.isNotEmpty(entity.getFlagshipSpeciesSeq())) {
                excel.setFlagshipSpeciesSeq(flagshipSpeciesSeq.get(entity.getId()));
            }
            if (entity.getSponsorship() != null) {
                excel.setSponsorship(entity.getSponsorship().intValue() == 1 ? "是" : "否");
            }
            if (entity.getLegend() != null) {
                excel.setLegend(entity.getLegend().intValue() == 1 ? "是" : "否");
            }
            dataList.add(excel);
        }
        return dataList;
    }
}
